package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"vip/models"
)

type VipController struct {
	beego.Controller
}
type DataMsg struct {
	Code int         `json:"Code"`
	Msg  string      `json:"Msg"`
	Data interface{} `json:"Data"`
}

func (c *VipController) List() {
	page, _ := c.GetInt("p", 1)
	pageSize, _ := c.GetInt("s", 5)
	name := c.GetString("name")
	vip, total, err := models.MysqlList(page, pageSize, name)
	if err != nil {
		c.Data["json"] = DataMsg{
			Code: 500,
			Msg:  "分页失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		jsonData := make(map[string]interface{})
		jsonData["vip"] = vip
		jsonData["total"] = total
		c.Data["json"] = DataMsg{
			Code: 200,
			Msg:  "分页成功",
			Data: jsonData,
		}
		c.ServeJSON()
	}
}
